package com.taeoneproject.desktoptapper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Gravity;
import android.view.View.OnTouchListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

public class KISActivity extends Activity {
	@Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.kis);
        
        doctor = (Button) findViewById(R.id.buttonDoctor);
        doctor.setOnTouchListener(listener);
  
        params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        
        timer.start();
    }
	
    OnTouchListener listener = new OnTouchListener () {
    	@Override
    	public boolean onTouch(View v, MotionEvent event) {
    		if (event.getAction() == MotionEvent.ACTION_DOWN)
    		{
    			goal++;
    			grav = (int) Math.round(Math.random()*2.0);
    			switch (grav) {
    				case 0: params.gravity = Gravity.LEFT; break;
    				case 1: params.gravity = Gravity.CENTER; break;
    				case 2: params.gravity = Gravity.RIGHT; break;
    			}
    			doctor.setLayoutParams(params);
    		}
    		return false;
    	}
    };
	
    CountDownTimer timer = new CountDownTimer ( 3 * 1000, 1000) {	
		@Override
		public void onTick(long millisUntilFinished) {
		}
		
		@Override
		public void onFinish() {
			if (goal >= 7)
				heal = true;
			else
				heal = false;
			Intent intent = new Intent();
			intent.putExtra("heal", heal);
			setResult(RESULT_OK, intent);
			finish();
			}
	};
	
    
    
	private Button doctor;
	private boolean heal = false;
	private LinearLayout.LayoutParams params;
	private int grav;
	private int goal = 0;
	public static final int CALL_KIS = 2;
}
